package com.briup.smartlabs.web.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.briup.smartlabs.bean.SmartLabs;
import com.briup.smartlabs.common.utils.Response;
import com.briup.smartlabs.service.LabsService;
import com.github.pagehelper.PageInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(tags = "实验室信息服务")
@RestController
@RequestMapping("/labs")
public class LabsController {

    @Autowired
    private LabsService labsService;
    @ApiOperation("批量删除实验室")
    @DeleteMapping("/batch")
    public Response<Map<String,List<String>>> removeLabsByIds(@RequestBody List<String> ids){

        Map<String,List<String>> map =labsService.removeByBatch(ids);
        return Response.ok(map);

    }

    @ApiOperation("按关键字查询实验室，带分页")
    @GetMapping("/by/condition")
    public Response<PageInfo<SmartLabs>> findByConditionByPage(@RequestParam(required = false) Integer pageNum,
                                         @RequestParam(required = false) Integer pageSize,
                                         @RequestParam(required = false) String key){
        PageInfo<SmartLabs> byCondition =labsService.findByCondition(pageNum,pageSize,key);
        return Response.ok(byCondition);
    }
    @ApiOperation("新增和编辑实验室")
    @PostMapping("/lab")
    public Response<String> saveOrEdit(@RequestBody SmartLabs smartLabs){
        labsService.saveOrUpdate(smartLabs);
        return Response.ok("操作成功");
    }

}









